package hanjia;

import java.util.ArrayList;
import java.util.List;

/**
 * Description:
 * Author:    Dane
 * CreateTime:2025/2/11-下午4:00
 * Since  :   1.0
 * Version:   1.0
 */
public class LeetCode404 {

    public int sumOfLeftLeaves(TreeNode root) {

        if (root.left==null&&root.right==null){
            return 0;
        }

        ArrayList<Integer> result = new ArrayList<>();


      findResult(root,result);
      int sum=0;
      for (int i:result){
          sum+=i;
      }
      return sum;

    }

    public void findResult(TreeNode root, List<Integer> result){
        if (root==null||root.left==null&&root.right==null){
            return ;
        }

        TreeNode left=root.left;
        if (left!=null&&left.left==null&&left.right==null){

                result.add(left.val);

        }
        findResult(root.left,result);
        findResult(root.right,result);


    }

}
